package com.project.webpage.controller;


import com.github.pagehelper.PageInfo;
import com.project.webpage.aop.TagLog;
import com.project.webpage.dto.SearchByRqRangeParam;
import com.project.webpage.entity.WorkCalendar;
import com.project.webpage.service.WorkCalendarService;
import com.project.webpage.util.RestResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/webpage/workcalendar/")
public class WorkCalendarController extends BaseController {

    @Resource
    WorkCalendarService workCalendarService;

    /**
     * 考核日历列表查询
     */
    @PostMapping("page")
    @TagLog(operation = 0, content = "查询考核日历列表")
    public RestResult page(@RequestBody SearchByRqRangeParam param) {
        this.getPage(true, param);
        return RestResult.ok(new PageInfo<>(workCalendarService.getListForPage(param)));
    }

    /**
     * 更新考核日历
     */
    @PutMapping("update")
    @TagLog(operation = 3, content = "更新考核日历")
    public RestResult update(@RequestBody WorkCalendar param) {
        try {
            List<WorkCalendar> list = workCalendarService.getByRq(param.getCalendar_date());
            if (list.size() == 0) {
                return RestResult.error("该条数据不存在");
            } else {
                workCalendarService.update(param, list.get(0).getCalendar_date());
                return RestResult.ok();
            }
        } catch (Exception e) {
            return RestResult.error(e.getMessage());
        }
    }
}
